package com.briup.jz.service.impl;

import com.briup.jz.bean.Comment;
import com.briup.jz.bean.CommentExample;
import com.briup.jz.bean.OrderComment;
import com.briup.jz.bean.OrderCommentExample;
import com.briup.jz.dao.CommentMapper;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.CustomerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public void saveOrUpdate(Comment comment) throws CustomerException {
        if(comment.getId()!=null){
            commentMapper.updateByPrimaryKey(comment);
        }else{
            commentMapper.insert(comment);
        }
    }

    @Override
    public List<Comment> query(String content) {
    	CommentExample example = new CommentExample();//创建模板
		if(content!=null){
			example.createCriteria().andCommentLike("%"+content+"%");
		}
		List<Comment> list = commentMapper.selectByExample(example);
		return list;
    }
 
    @Override
    public void deleteById(long id) throws CustomerException {
        Comment comment = commentMapper.selectByPrimaryKey(id);
        if (comment==null){
            throw  new CustomerException("删除的评论不存在");
        }else {
            commentMapper.deleteByPrimaryKey(id);
        }

    }
}
